package com.huike.clues.service.impl;


import cn.hutool.core.bean.BeanUtil;
import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {

    @Autowired
    private TbClueMapper tbClueMapper;
    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;


    /**
     * 查询线索跟进记录列表
     * @param clueId
     * @return
     */
    @Override
    public List<TbClueTrackRecord> list(Long clueId) {
        TableDataInfo tableDataInfo = new TableDataInfo();
       List<TbClueTrackRecord> list = tbClueTrackRecordMapper.getListByClueId(clueId);
        return list;
    }

    /**
     * 添加线索跟进
     * @param tbClueTrackRecord
     * @return
     */
    @Override
    public AjaxResult add(ClueTrackRecordVo tbClueTrackRecord) {
        //获取创建人
        String username = SecurityUtils.getUsername();
        //修改线索对象
        TbClue tbClue = new TbClue();
        BeanUtil.copyProperties(tbClueTrackRecord,tbClue);
        tbClue.setId(tbClueTrackRecord.getClueId());
        //获取当前时间
        Date nowDate = DateUtils.getNowDate();
        tbClue.setUpdateTime(nowDate);
         //修改线索表
       tbClueMapper.updateTbClue(tbClue);

        //添加线索跟进表
        TbClueTrackRecord tb = new TbClueTrackRecord();
        BeanUtil.copyProperties(tbClueTrackRecord,tb);
        tb.setCreateBy(username);
        tb.setCreateTime(nowDate);
        tb.setType("0");
        tbClueTrackRecordMapper.inster(tb);
        return AjaxResult.success("操作成功");
    }
}
